Skip to content

fix(mcp): answer malformed request params as -32602 Invalid params naming the param - #29205

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-5zqs9f
Nov 2, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-5zqs9f

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread
Fixes #29135

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:MCP 请求参数格式不对(如 prompts/get 不带 name、tools/call 传 {})时,服务器现在回 JSON-RPC -32602「参数无效」,并用一句英文点名哪个参数错了(params.name is required),不再回 -32603「内部错误」加一段 Zod 原始 JSON。
  • 为什么改:-32603 告诉调用方「服务器坏了」,AI 代理会当成可重试错误反复重发一个永远不会成功的请求;开发者看到的是一堆 Zod 内部结构,而不是一句话。
  • 风险与回滚:同样的请求照样被拒,只是错误码和文字变了;工具自身的参数校验(如 validate_expression 的 site 枚举)和处理函数内部抛出的错误都不受影响。回滚即回退本 PR。
  • 先看:packages/mcp/src/request-params.ts(唯一的接缝,读 SDK 未公开的请求处理表,缺失时构造即报错)、packages/mcp/src/mcp-server-runtime.ts 两处建服务器的调用点、packages/mcp/src/request-params.test.ts。
  • 两分钟验证:pnpm --filter @objectstack/mcp exec vitest run src/request-params.test.ts,预期 7 个测试全绿。
  • 需要你做的:无,席位落地。

What changes

  • New packages/mcp/src/request-params.ts with createPlatformMcpServer(...), now the only place the platform builds an MCP McpServer. Both transports use it: the long-lived (stdio) server in the MCPServerRuntime constructor and the per-request Streamable HTTP server in handleHttpRequest.
  • It wraps every request dispatcher the SDK's low-level Server holds, the ones the SDK installs in its own constructor (initialize, ping) and every later one (tools/call, prompts/get, resources/read, …). A ZodError thrown synchronously by a dispatcher is the method's request-schema parse (the SDK parses before it calls the async handler), and it is rethrown as McpError(ErrorCode.InvalidParams, sentence). A ZodError raised inside a handler arrives as a rejected promise and keeps its own answer.
  • Sentence: one plain-English clause per issue, joined with ; : params.name is required (the value is absent), params.name must be a string (wrong type), must be one of … (enum or literal), has unrecognized key(s): …. Any other issue falls back to the shared formatZodIssue from @objectstack/spec/shared. McpError adds its own MCP error -32602: prefix.
  • No new error code: -32602 is the JSON-RPC standard one the SDK already uses for its own invalid-params answers. No packages/spec/** edit, no lockfile change, no new gate.

Why

The SDK's Protocol.setRequestHandler (measured on the installed @modelcontextprotocol/sdk 1.32.1, and unchanged in the latest 1.32.2) installs a closure that parses the request with the method's schema and rethrows the ZodError unchanged. A ZodError has no numeric code, so the protocol answers -32603 Internal error with the error's message, which is the serialised issue array. The SDK offers no public hook between that parse and the error answer, so the seam reads the protocol's _requestHandlers map. That is an SDK-internal field, so the seam checks it is there: if a later SDK renames it, server construction throws an error that names this function, and the -32603 answer does not come back silently.

Measured on base 0d6d4061 (in-process, same calls as the card):

Request Base Head
prompts/get {} (HTTP) -32603, Zod issue array -32602 params.name is required
tools/call {} (HTTP) -32603, Zod issue array -32602 params.name is required
prompts/get {"name":42} (HTTP) -32603, Zod issue array -32602 params.name must be a string
tools/call {} (stdio, long-lived server) -32603, Zod issue array -32602 params.name is required
control: validate_expression with site: "nope" tool result isError, MCP error -32602: Input validation error: … unchanged

Clause-② measured: the same requests are refused on base and head (no request accepted on one side is refused on the other), so no. Only the error class and the message change.

Tests

packages/mcp/src/request-params.test.ts (new, 7 cases):

  • HTTP: prompts/get with no name, tools/call with {}, prompts/get with name: 42, and initialize with no protocolVersion (a handler the SDK installs in its own constructor). Each asserts error.code === -32602 and the full message.
  • stdio: tools/call with {} on the long-lived server over a real StdioServerTransport.
  • Control: validate_expression with an unknown site keeps its tool-result answer.
  • Negative pin: a ZodError thrown inside a handler keeps -32603.

No existing test was edited.

Acceptance notes

  • resources/read with malformed params: neither server in these tests registers resources, so it answers -32601 Method not found there. The seam is method-agnostic (it wraps the map, not a method list), and the initialize pin proves that a handler installed outside the platform's own registration is covered too.
  • Upstream: the SDK could map the request-schema ZodError to InvalidParams itself; when it does, this seam can go. That is noted in the report's open questions, not filed.

Verification

All readings at head 7bff29ad unless noted.

Ablations (both restored, `git diff HEAD` empty, blob == HEAD)
  • Mapping removed (answerMalformedParamsAsInvalidParams(server); deleted through scripts/ablation-replace.mjs, anchor 1 → 0, at 1d7f90e): 5 failed, 2 passed. Each failure is expected -32603 to be -32602. The control and the inner-ZodError pin stay green.
  • Discriminator widened (the guard also maps a ZodError that a handler rejects with): only a ZodError thrown inside a handler keeps the -32603 answer fails, expected -32602 to be -32603. 6 passed.
Suites
  • pnpm --filter @objectstack/mcp test: Test Files 54 passed (54), Tests 651 passed (651).
  • pnpm --filter @objectstack/mcp typecheck (tsc + check:test-typecheck): exit 0.
  • @objectstack/runtime MCP domain tests (src/domains/mcp-{federation-bridge,merged-skill-read,option-fields-read,package-object-discovery}.test.ts, after building @objectstack/runtime^...): Test Files 4 passed (4), Tests 162 passed (162).
  • eslint over packages/mcp (--no-inline-config): exit 0.
Gates (dispatch-gates --commands, 59 derived)
  • node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack at 7bff29ad: 59 commands derived; 4 changed paths, 302 changed lines.
  • Exit 0 for 57 of them as first run.
  • node scripts/check-plugin-teardown-shape.mjs --self-test: exit 3 on the first run (its positive-control commit was outside the shallow clone). Exit 0 after git fetch --unshallow origin main (48 cases pass).
  • pnpm check:dual-build-cjs-loads: exit 3, PREREQUISITE NOT MET (it needs every package's dist/; only the @objectstack/runtime closure was built here). NOT MEASURED locally; CI's Lint & Repo Gates runs it.
  • --ran reconciliation: 59 derived, 58 run, 1 NOT-MEASURED, 0 UNRUN.

🤖 Generated with Claude Code · https://claude.ai/code/session_01ADHkmT3dPW9V7vSk6VKtuN


Generated by Claude Code

…th a readable sentence

Both MCP transports now build their server through createPlatformMcpServer,
which maps a request-schema parse failure to JSON-RPC -32602 naming the param
(`params.name is required`) instead of the SDK's -32603 Internal error carrying
the serialised Zod issue list.

Claude-Session: https://claude.ai/code/session_01ADHkmT3dPW9V7vSk6VKtuN
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/mcp, touching 11 documentable anchor(s).

10 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/api/error-catalog.mdx (via invalid_type (literal, a string literal in invalidParamsSentence), invalid_value (literal, a string literal in invalidParamsSentence))
  • content/docs/api/error-handling-server.mdx (via invalid_type (literal, a string literal in invalidParamsSentence))
  • content/docs/api/plugin-endpoints.mdx (via invalid_value (literal, a string literal in invalidParamsSentence))
  • content/docs/automation/flows.mdx (via invalid_type (literal, a string literal in invalidParamsSentence), invalid_value (literal, a string literal in invalidParamsSentence))
  • content/docs/data-modeling/field-types.mdx (via invalid_value (literal, a string literal in invalidParamsSentence))
  • content/docs/data-modeling/validation-rules.mdx (via invalid_value (literal, a string literal in invalidParamsSentence))
  • content/docs/deployment/cli.mdx (via invalid_type (literal, a string literal in invalidParamsSentence), unrecognized_keys (literal, a string literal in invalidParamsSentence))
  • content/docs/frontend/cli.mdx (via invalid_type (literal, a string literal in invalidParamsSentence))
  • content/docs/protocol/objectql/types.mdx (via unrecognized_keys (literal, a string literal in invalidParamsSentence))
  • content/docs/protocol/objectui/concept.mdx (via invalid_type (literal, a string literal in invalidParamsSentence))

⛔ 3 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v17/17-0.mdx (via invalid_type (literal, a string literal in invalidParamsSentence), unrecognized_keys (literal, a string literal in invalidParamsSentence))
  • content/docs/releases/v17/17-6.mdx (via invalid_type (literal, a string literal in invalidParamsSentence))
  • content/docs/releases/v18/18-2.mdx (via invalid_value (literal, a string literal in invalidParamsSentence))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 3 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 60 of 216 client-bound route-ledger rows — the other 156 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 156: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 101 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 12 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 692e0dc8b936ad37311352868083d78745c76a21 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 68befdb32b6d26fe7980765ac355536afa85e5ae — the merge of head 7bff29ad7389d1c21f14868901f85b9364d20c0e into base 692e0dc8b936ad37311352868083d78745c76a21, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 68befdb32b6d26fe7980765ac355536afa85e5ae && git checkout 68befdb32b6d26fe7980765ac355536afa85e5ae
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 692e0dc8b936ad37311352868083d78745c76a21 7bff29ad7389d1c21f14868901f85b9364d20c0e && git checkout -B drift-repro 692e0dc8b936ad37311352868083d78745c76a21 && git merge --no-ff 7bff29ad7389d1c21f14868901f85b9364d20c0e

node scripts/docs-audit/affected-docs.mjs --json 692e0dc8b936ad37311352868083d78745c76a21

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 692e0dc8b936ad37311352868083d78745c76a21 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY

席位核对 · ACCEPT · domain:server seat 1 · os-steve · session_01ADHkmQjPiXgNoSaEpqeGvY · 2026-11-02T09:21Z

Head 7bff29ad73, report 6573483616 (on #29135), claim 6572639208. Clause-②: no, no arm: the same requests are refused on base and head, only the JSON-RPC code and sentence change, so no contract review is owed. The seat read the diff itself.

item reading
Shape Draft, base main, Fixes #29135. 4 files (+300 / −2): new packages/mcp/src/request-params.ts (createPlatformMcpServer), both new McpServer(...) sites in mcp-server-runtime.ts (long-lived stdio server and the per-request HTTP server) moved onto it, request-params.test.ts, a @objectstack/mcp patch changeset. Metadata-protocol: none. No packages/spec/**, no new code beyond JSON-RPC's own -32602, no lockfile bump, no gate. Not governed.
Rule One seam: every request dispatcher in the SDK protocol's handler map (constructor-installed and later-registered) is wrapped so a SYNCHRONOUS $ZodError (the request-schema parse, which the dispatcher runs before calling the async handler) is rethrown as McpError(InvalidParams) with a plain sentence (params.name is required / must be a string, else the shared Zod issue formatter). A ZodError from inside a handler arrives as a rejection and keeps its own answer, so the control (validate_expression bad site → -32602) is unchanged.
Accepted deviation The seam reads the SDK's private _requestHandlers map: the SDK offers no public hook between the parse and the error answer (measured 1.32.1 installed, 1.32.2 latest). Its absence throws at server construction with the function's name, so an SDK rename fails loudly instead of returning to -32603. Accepted as the narrowest fix; the long-term fix is upstream.
Evidence Base 0d6d4061: -32603 + Zod dump on the three card requests over HTTP and on tools/call {} over stdio. Head: mcp 54 files / 651 green, runtime MCP domain 4 files / 162 green, typecheck 0, eslint 0; two ablations red, restore clean. Gates 59 derived, 58 run, check:dual-build-cjs-loads NOT MEASURED (full build), left to CI. CI on this head is running; auto-merge waits for every check green or an expected skip.
Open question Report the gap to the SDK upstream: not this PR; noted on the card for the maintainer, no card filed (an upstream issue is an outward act).
Out of scope none.
Landing 「按照 pm-dispatch 规则复核过的都授权」 (Leehom, 2026-10-25T11:35Z): ready and auto-merge through the relay.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 2, 2026 09:22
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 2, 2026 09:22
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit 1b22286 Nov 2, 2026
49 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-5zqs9f branch November 2, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

1 participant